package com.yanqu.road.server.logic.activity.condition.daomu;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.BaseActivityCondition;
import com.yanqu.road.utils.string.StringUtils;

import java.math.BigInteger;
import java.util.List;

public class DaoMuPvpExpCondition extends BaseActivityCondition {

    public DaoMuPvpExpCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
        super(activityInfo, activityConditionInfo, baseActivityData);
    }

    @Override
    protected void player_BoardLevelHandle(Object object) {
        if (activityInfo.getType() == eActivityType.DaoMu.getValue()) {
            DaoMuPvpExpArgs args = (DaoMuPvpExpArgs) object;
            List<BigInteger> paramList = getActivityConditionInfo().getParamList();
            if (paramList.get(0).equals(BigInteger.valueOf(args.getRound()))) {
                setValue(getValue().add(BigInteger.valueOf(args.getAddExp())));
            }
        }
    }

    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.DaoMuPvpExp.getValue(), handle);
    }

    @Override
    public void removeTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.DaoMuPvpExp.getValue(), handle);
    }

    @Override
    public boolean isCompleted(GamePlayer player) {
        return getValue().compareTo(activityConditionInfo.getParamList().get(3)) >= 0;
    }
}
